<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	public function index()
	{
		//$this->load->view('welcome');
		echo "Welcome bro"."<br /><br />";
		
		// ------------------------------------------------ Reset Tiap Bulan untuk Generator -----------------
		
		// $febs = ($d->th%100 > 0 ? ($d->th%4 == 0 ? ($d->th%400 > 0 ? 1:0):0):0)+28;
		$sekarang = mdate("%Y%m", time());
		
		$historyP = $this->db->where(array('param' => 'PENAWARAN'))->get('init')->result();
		$data = trim($historyP[0]->bulan);
		
		$s = new StdClass();
		$s->th = mdate("%Y", time());
		$s->bln = mdate("%m", time());
		
		$d = new StdClass();
		$d->th = substr($data,0,4);
		$d->bln = substr($data,4,2);
		
		$reset = 0;
		
		if($s->bln > $d->bln && $s->bln != $d->bln){
			if($s->th >= $d->th){
				$reset = 11;
				// $this->db->where('param','PENAWARAN')->update('init',array('bulan' => $sekarang, 'value' => 1));
			}
		}
		else {
			if($s->th > $d->th){
				$reset = 12;
				// $this->db->where('param','PENAWARAN')->update('init',array('bulan' => $sekarang, 'value' => 1));
			}
		}
		
		echo $reset . "<br />";
		
		$ubah = ($s->bln > $d->bln && $s->bln != $d->bln ? ($s->th >= $d->th ? $this->db->where('param','PENAWARAN')->update('init',array('bulan' => $sekarang, 'value' => 1)) :0):($s->th > $d->th ? $this->db->where('param','PENAWARAN')->update('init',array('bulan' => $sekarang, 'value' => 1)) :0));
		
		// echo $s->bln . " " . $d->bln . " " . $ubah;
		
		// ---------------------------------------------------------------------------------------------------
		
		
		
		/* $group_id = 2;
		$list= $this->db->query("SELECT vu_tree_menus.menu_title as TREE_MENU_TITLE,
				s_permissions.PERM_ID, 
				".$group_id." AS PERM_GROUP, 
				vu_tree_menus.MENU_ID AS PERM_MENU, 
				vu_tree_menus.MENU_PARENT AS MENU_PARENT,
				IF(s_permissions.PERM_PRIV IS NULL,0,1) AS PERM_PRIV
			FROM vu_tree_menus
			LEFT JOIN s_permissions ON(s_permissions.PERM_MENU = vu_tree_menus.MENU_ID AND s_permissions.PERM_GROUP = ".$group_id.")")->result();
		echo sizeof($list)."<br /><br />";
		
		$n = $this->db->get_where('s_menus',array('menu_parent'=> 0))->num_rows();
		
		$isi = array();
		
		for($i=0;$i<$n;$i++)
		{
			$data = new stdClass();
			$data->TREE_MENU_TITLE = $list[$i]->TREE_MENU_TITLE;
			$data->PERM_ID = $list[$i]->PERM_ID;
			$data->PERM_GROUP = $list[$i]->PERM_GROUP;
			$data->PERM_MENU = $list[$i]->PERM_MENU;
			$data->MENU_PARENT = $list[$i]->MENU_PARENT;
			$data->PERM_PRIV = $list[$i]->PERM_PRIV;
			array_push($isi,$data);
			
			foreach($list as $v)
			{
				if($v->MENU_PARENT != 0 && $v->MENU_PARENT==($i+1))
				{
					$data = new stdClass();
					$data->TREE_MENU_TITLE = $v->TREE_MENU_TITLE;
					$data->PERM_ID = $v->PERM_ID;
					$data->PERM_GROUP = $v->PERM_GROUP;
					$data->PERM_MENU = $v->PERM_MENU;
					$data->MENU_PARENT = $v->MENU_PARENT;
					$data->PERM_PRIV = $v->PERM_PRIV;
					array_push($isi,$data);
				}
			}
		}
		echo sizeof($isi)."<br /><br />";
		foreach($isi as $v)
		{
			echo $v->TREE_MENU_TITLE."<br />";
		} */
	}
	
	function GenSG($pathjs="", $table="")
	{
		$path = './application'; //ini adalah path application CI
		$nfile = $table; // ini adalah namafile bisa berdasar nama tabel
		//$tbl = 'cutitahunan';   // ini adalah nama tabel
		$data['fields'] = $this->db->field_data($table);
		$data['pathjs'] = $pathjs;		//ini adalah nama path View misal : Master,Proses,Aksess,dll
		$this->egen->SingleGrid($path,$nfile,$table,$data);  // ini adalah eksekusi Utama Generator
	}
	
	function GenSGSF($pathjs="", $table="")
	{
		$path = './application'; //ini adalah path application CI
		$nfile = $table; // ini adalah namafile bisa berdasar nama tabel
		//$tbl = 'cutitahunan';   // ini adalah nama tabel
		$data['fields'] = $this->db->field_data($table);
		$data['pathjs'] = $pathjs;		//ini adalah nama path View misal : Master,Proses,Aksess,dll
		$this->egen->SingleGridSF($path,$nfile,$table,$data);  // ini adalah eksekusi Utama Generator
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */